<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<%-- Start of dataTables--%>
<link rel="stylesheet" href="${ctx}/static/css/dataTables/dataTables.fontAwesome.css" />
<link rel="stylesheet" href="${ctx}/static/css/dataTables/dataTables.bootstrap.css" />
<script src="${ctx}/static/js/lib/dataTables/jquery.dataTables.min.js"></script>
<script src="${ctx}/static/js/lib/dataTables/dataTables.bootstrap.js"></script>
<%-- End of dataTables--%>
<script type="text/javascript">
$(document).ready(function() {
	  $('#example').dataTable({
		    language: {
		        "sProcessing": "处理中...",
		        "sLengthMenu": "显示 _MENU_ 项结果",
		        "sZeroRecords": "没有匹配结果",
		        "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
		        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
		        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
		        "sInfoPostFix": "",
		        "sSearch": "搜索:",
		        "sUrl": "",
		        "sEmptyTable": "暂无角色信息",
		        "sLoadingRecords": "载入中...",
		        "sInfoThousands": ",",
		        "oPaginate": {
		            "sFirst": "首页",
		            "sPrevious": "上页",
		            "sNext": "下页",
		            "sLast": "末页"
		        },
		        "oAria": {
		            "sSortAscending": ": 以升序排列此列",
		            "sSortDescending": ": 以降序排列此列"
		        }
		    },
		    "pagingType": "full_numbers",
		    "lengthMenu": [ [ 5, 10, 25, 50, 75, 100, -1 ], [ 5, 10, 25, 50, 75, 100, "所有" ] ],
		    "displayLength": 5,
		    "order": [[ 6, "desc" ]],
		    "columnDefs": [ {
		        "targets": 'nosort',
		        "orderable": false
		      } ]
		});
		  $('table.display')
			.removeClass( 'display' )
			.addClass('table table-striped table-bordered');
	} );

function addUserRole(userId){
    var curCheck = document.getElementsByName("roleAddChecked");
    var curRoleCheck = "";
    for(var i=0;i<curCheck.length;i++){
        var temp=document.getElementsByName("roleAddChecked")[i];
        if(temp.checked){
            curRoleCheck = curRoleCheck + temp.value + ",";
        }
    }
    if(curRoleCheck.length == 0){
		ui.msg('请至少选择一条要增加的记录!');
		return;
	}
    $.ajax({
           type: "POST",
           dataType:"json",
           cache: false,
           url: _ctx + "/pub/sysmgr/usermgr/add_user_role_role.do",
           data: {userId:userId,roleIds:curRoleCheck},
           beforeSend : function(){
           },
           success: function(resp){
               if(resp.status == '1'){
                   ui.msg(resp.msg, 1);
                   $('#toIframeModal').modal('hide');
                   $('#content')[0].contentWindow.ui.go(_ctx + '/pub/sysmgr/usermgr/user_role_choose_role.do?userId='+userId);
               }else{
                   ui.msg(resp.msg, 0);
               }
           },
           error:function(){
               ui.msg( '请求发送失败！',0 );
           }
    });  
}
</script>
<div class="table-responsive">
	<div class="row">
		<div class="col-xs-12">
			<div class="widget-header widget-header-flat">
	            <h5 class="smaller lighter">
	                <i class="icon-list"></i> &nbsp;
	            </h5>
	            <div class="widget-toolbar no-border">
                    <a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="addUserRole('${vo.id}')">
                        <i class="icon-plus-sign"></i> 添加选中的角色&nbsp;
                    </a>
				</div>
	        </div>
			<div class="widget-main">
				<div id="optDiv">
	                <div class="table-responsive">
	                    <table id="example" cellspacing="0" width="100%" class="display">
	                        <thead>
								<tr>
									<th class="center nosort" style="padding-right: 8px;">
										<label>
										<input type="checkbox" class="ace" onclick="$.checkBoxTriggerAll(this,'roleAddChecked')"/>
										<span class="lbl"></span>
										</label>
									</th>
									<th style="word-break: keep-all;white-space:nowrap;">角色编码</th>
									<th style="word-break: keep-all;white-space:nowrap;">角色名称</th>
									<th style="word-break: keep-all;white-space:nowrap;">角色类型</th>
									<th style="word-break: keep-all;white-space:nowrap;">所属机构</th>
									<th style="word-break: keep-all;white-space:nowrap;">状态</th>
									<th style="word-break: keep-all;white-space:nowrap;">公共角色</th>
									<th style="word-break: keep-all;white-space:nowrap;">创建时间</th>
									<th style="word-break: keep-all;white-space:nowrap;">描述</th>
								</tr>
							</thead>
	                
	                        <tbody>
	                            <c:forEach var="vo" items="${otherRoleInfoList}">
								<tr>
									<td class="center">
										<label>
										<input name="roleAddChecked" type="checkbox" class="ace" value="${vo.id}"/>
										<span class="lbl"></span>
										</label>
									</td>
									<td>${vo.roleCode}&nbsp;</td>
									<td>${vo.roleName}&nbsp;</td>
									<td>${cm:ctname('authusertype',vo.roleType)}&nbsp;</td>
									<td>${vo.orgCode}&nbsp;</td>
									<td>${cm:ctname('entity_status',vo.roleStatus)}&nbsp;</td>
									<td>${cm:yesNoStr(vo.isDefault)}&nbsp;</td>
									<td><fmt:formatDate value="${vo.modified}" pattern="yyyy-MM-dd HH:mm:ss" />&nbsp;</td>
									<td>${vo.remark}&nbsp;</td>
								</tr>
								</c:forEach>
	                        </tbody>
	                    </table>
	                </div>
	            </div>
			</div>
		</div>
	</div>
</div>
